Skip to content

Critical Actions - #166

Merged
LeVraiArdox merged 37 commits into
mainfrom
Critical-Actions
Nov 13, 2026
Merged

LeVraiArdox merged 37 commits into
mainfrom
Critical-Actions

Conversation

@Abscissa24

@Abscissa24 Abscissa24 commented Oct 5, 2026 •

Copy link
Copy Markdown
Member

Critical Actions

  • Perform specific actions when the battery reaches a certain threshold
  • Prevents the machine from dying by entering an emergency sleep | hibernate | shutdown | lock
  • My laptop has died way too many times so I figured this would be useful

Demo

New options in Behaviour → Power

image

Showcase

demo.mp4

@Abscissa24 Abscissa24 linked an issue Oct 5, 2026 that may be closed by this pull request
@LeVraiArdox

Copy link
Copy Markdown
Member

Looks good, but I don't see why a lockscreen would be useful here. Just remove this one.

Else, it's a good idea. I'll review later

@LeVraiArdox LeVraiArdox left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename "critical actions" to "Critical charge behavior", it's clearer. Thanks

Comment thread src/share/sleex/services/Battery.qml Resolved

@LeVraiArdox LeVraiArdox left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still some changes to be made (including merge from main to update). Also, I don't like the fact that you added two different features in the same PR (bar auto hide and critical actions). Keep it this time, but know it for next time

Comment thread src/share/sleex/services/Battery.qml Resolved
@Abscissa24

Copy link
Copy Markdown
Member Author

@LeVraiArdox things should be a bit better now

image
demo.mp4

@LeVraiArdox

Copy link
Copy Markdown
Member

Can you stick it to the borders ? of the screen ?

@Abscissa24

Copy link
Copy Markdown
Member Author
updated-demo.mp4

@LeVraiArdox

Copy link
Copy Markdown
Member

That's good. Can you update your branch before the final review plz

# Conflicts:
#	src/share/sleex/modules/bar/Bar.qml
@sonarqubecloud

Copy link
Copy Markdown

Comment thread src/share/sleex/shell.qml Resolved

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A critical battery countdown overlay is a great addition, but burning through the last 2% of battery by rendering full-screen MSAA FBOs every frame is delightfully ironic.

1. Broken ShapePath trimming (CriticalBatteryOverlay.qml)

ShapePath in QtQuick.Shapes does not expose a grouped trim property. The Qt properties are trimStart and trimEnd:

EdgePath {
    trimStart: 0
    trimEnd: Math.max(win.prog, 0.002)
}

Using trim.start and trim.end will throw a runtime QML property error and fail to animate the snake stroke.

2. Unnecessary full-screen layer.enabled FBOs (CriticalBatteryOverlay.qml)

Shape {
    id: snakeShape
    anchors.fill: parent
    layer.enabled: Battery.criticalActionWanted
    layer.smooth: true
    layer.samples: 2
}

anchors.fill: parent spans the entire display resolution. Enabling layer.enabled with layer.samples: 2 forces Qt to allocate full-screen multi-sampled offscreen framebuffers. Since snakeShape animates prog at display refresh rate over 30 seconds, Qt will continuously re-render and resolve a multi-gigabyte/s MSAA pipeline while the machine is on its last drops of power.

Shape and ShapePath already handle vector antialiasing on the GPU. Remove layer.enabled, layer.smooth, and layer.samples from both trackShape and snakeShape.

3. Eager LazyLoader (shell.qml)

LazyLoader { active: true; component: CriticalBatteryOverlay {} }

Setting active: true defeats the purpose of LazyLoader. This keeps Wayland PanelWindow surfaces instantiated on every connected screen permanently for an event that happens once in a blue moon. Bind active conditionally:

LazyLoader {
    active: Battery.criticalActionWanted
    component: CriticalBatteryOverlay {}
}

4. Double toggle bug in BehaviorConfig.qml

ConfigSwitch {
    text: "Enable critical charge behavior"
    checked: Config.options.battery.criticalActionEnabled
    onClicked: checked = !checked;
    onCheckedChanged: {
        Config.options.battery.criticalActionEnabled = checked;
    }
}

Switch / AbstractButton controls automatically invert checked on user click. Manually doing onClicked: checked = !checked in addition to onCheckedChanged will toggle the switch twice (cancelling out the user interaction) or break the property binding.

The two full screen Shape items each allocated a multisampled offscreen
buffer through layer.enabled, which is expensive on high resolution or
multi monitor setups. The curve renderer antialiases the strokes on the
GPU instead, so the offscreen buffers are not needed.

The countdown border is also no longer loaded before the countdown runs,
so its layer surfaces only exist while they are actually needed.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Critical Issues

  • Non-existent property on ShapePath (CriticalBatteryOverlay.qml:111-112):

    EdgePath {
        trim.start: 0
        trim.end: Math.max(win.prog, 0.002)
    }

    ShapePath in QtQuick.Shapes does not have a trim property (grouped or otherwise). This looks like SwiftUI's .trim() or Flutter leaking in. When Battery.criticalActionWanted triggers and LazyLoader tries to instantiate CriticalBatteryOverlay, QML will fail with Cannot assign to non-existent property "trim" and the overlay will fail to load entirely.

    To animate path progress in QtQuick.Shapes, you typically need to set strokeStyle: ShapePath.DashLine and drive dashPattern / dashOffset based on the path perimeter, or compute the arc/line endpoints directly.


Quality & Logic Observations

  • ConfigSwitch click handler (BehaviorConfig.qml:141):

    onClicked: checked = !checked;
    onCheckedChanged: {
        Config.options.battery.criticalActionEnabled = checked;
    }

    Manually toggling checked = !checked in onClicked will break the property binding on checked and cause double-toggles if the underlying switch control already toggles on click. Let the switch handle state or bind two-way cleanly.

  • Default fallback mismatch (CriticalBatteryOverlay.qml:13-15):
    Config.qml specifies defaults of thickness 5 and corner radius 25, while CriticalBatteryOverlay.qml falls back to 14 and 20. Align the fallbacks to avoid surprises if config properties are uninitialized.

  • Bar Reflow Removal (Bar.qml):
    Removing criticalShift and managing layer order via rules.lua (order = 1) is a great cleanup. Dynamic exclusiveZone adjustments during battery states caused unnecessary desktop reflows.

The fallback values were left over from the first version of the overlay
and no longer matched the defaults in modules/common/Config.qml.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blockers

  1. Unreleased Qt Dependency (ShapePath.trim in Qt 6.10)
    In CriticalBatteryOverlay.qml:

    // ShapePath.trim is a property group (QQuickShapeTrim, added
    // in Qt 6.10) holding fractions of the path length, so the
    // snake stroke grows along the border as the countdown runs.
    trim.start: 0
    trim.end: Math.max(win.prog, 0.002)

    As noted in your own comment, ShapePath.trim requires Qt 6.10. Current stable distributions are on Qt 6.8 (with 6.9 only just entering release cycles), meaning Qt 6.10 is an unreleased future target. Running this on current systems will fail at QML compilation time with:

    Cannot assign to non-existent property "trim"
    

    Because shell.qml declares CriticalBatteryOverlay {} inside a LazyLoader, this parse failure will prevent the shell from starting altogether. You need to implement the snake stroke using current APIs (for example, adjusting dashPattern / dashOffset on ShapePath, computing path arc/line lengths dynamically, or rendering via a shader) until Qt 6.10 is actually released and Sleex raises its minimum Qt requirement.

  2. Broken Switch Toggle in Settings
    In BehaviorConfig.qml:

    ConfigSwitch {
        text: "Enable critical charge behavior"
        checked: Config.options.battery.criticalActionEnabled
        onClicked: checked = !checked;
        onCheckedChanged: {
            Config.options.battery.criticalActionEnabled = checked;
        }
    }

    Switch / checkable controls already toggle their checked state when clicked. Toggling checked = !checked in onClicked inverts the state twice on every click, effectively preventing users from toggling the setting properly. Remove onClicked: checked = !checked;.


Suggestions & Commendations

  • Good cleanup in Bar.qml: Removing criticalShift and the dynamic exclusiveZone height recalculation in favor of Hyprland's order = 1 layer rule avoids expensive window manager reflows when the battery goes critical.

The critical battery overlay uses ShapePath.trim, which was added in
Qt 6.10, so the shell no longer runs on older Qt.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Elephant in the Time Machine

  • Hard requirement on unreleased Qt 6.10 (CMakeLists.txt & CriticalBatteryOverlay.qml):
    qt_standard_project_setup(REQUIRES 6.10) will immediately fail CMake configuration on basically every distribution out there today (Qt 6.8 is the current LTS, and Qt 6.10 is not even out). Sleex cannot build on Arch, Fedora, or NixOS with this requirement.
    While ShapePath.trim (QQuickShapeTrim) in Qt 6.10 is nice, you don't need a future Qt version just to draw a creeping border snake. You can achieve stroke trimming on Qt 6.8/6.9 using strokeDashArray and strokeDashOffset on ShapePath (setting the dash length to the perimeter and animating the offset), or drawing via a simple shader/QQuickPaintedItem.

Performance & Re-renders

  • 144Hz text relayout in BatteryPopup.qml:
    text: {
        const remain = Math.max(0, Math.ceil((1 - Battery.criticalActionProgress) * Config.options.battery.criticalActionDelay))
        return qsTr("%1 in %2s").arg(Battery.criticalActionLabel).arg(remain)
    }
    Binding text directly to Battery.criticalActionProgress (which is continuously ticked by a NumberAnimation) will re-evaluate, format the string, and recalculate text layouts on every single frame for 30+ seconds. Drive the countdown text using a 1-second Timer or a discrete remainingSeconds integer property on Battery instead of animating the text layout on every vsync tick.

The Good Stuff

  • Killing dynamic exclusiveZone in Bar.qml: Removing criticalShift and its dynamic exclusiveZone changes is a great cleanup. Fiddling with exclusiveZone during a battery warning was forcing Hyprland to repeatedly reflow all windows and workspace layouts.
  • No FBO waste: Good job using preferredRendererType: Shape.CurveRenderer without layer.enabled on full-screen windows in CriticalBatteryOverlay.qml.

The label was bound to the countdown progress, which is animated on every
frame, so the binding and the string formatting ran at the frame rate for
the whole countdown. Round the remaining time down to whole seconds on the
Battery service instead, so the label is only rebuilt when the number
actually changes.
The 6.10 bump was only there to match ShapePath.trim, which the countdown
border uses. The requirement stays where upstream has it.
The border warns about a dying battery, so it should use the same error
colour as the countdown text in the battery popup instead of the regular
accent colour.
The accent colour is what the border should use; the error colour is
reserved for the countdown text in the battery popup.

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Blocker: Hallucinated ShapePath.trim property

In src/share/sleex/CriticalBatteryOverlay.qml:

EdgePath {
    // ShapePath.trim is a property group (QQuickShapeTrim) that
    // holds fractions of the path length, so the snake stroke
    // grows along the border as the countdown runs.
    trim.start: 0
    trim.end: Math.max(win.prog, 0.002)
}

Neither trim nor QQuickShapeTrim exists in QtQuick.Shapes (in Qt 6.x or any Qt version). When Battery.criticalActionWanted flips to true and LazyLoader instantiates CriticalBatteryOverlay, QML will fail with a fatal runtime error: Cannot assign to non-existent property "trim".

To achieve this stroke countdown effect in QtQuick, you need to either:

  1. Use dash strokes via strokeStyle: ShapePath.DashLine, driving dashPattern: [win.prog * totalPathLength, totalPathLength] and dashOffset: 0.
  2. Dynamically calculate and clamp the sub-segments (PathLine lengths and PathAngleArc sweep angles) across the 4 borders.
  3. Render the stroke progress via a Canvas context or a custom shader.

Semantic Color Token

In CriticalBatteryOverlay.qml:

strokeColor: Appearance.colors.colPrimary

This is a critical countdown overlay warning the user of imminent shutdown/suspend. In BatteryPopup.qml, the remaining time label correctly uses Appearance.colors.colError, but the overlay border uses Appearance.colors.colPrimary. Consider switching this to Appearance.colors.colError so the whole screen doesn't turn accent-colored for a fatal battery state.


Commendation

Removing criticalShift from Bar.qml (which previously mutated exclusiveZone and implicitHeight on the bar) in favor of Hyprland's layer order rule is a great change—it eliminates unnecessary desktop reflows.

@Abscissa24

Copy link
Copy Markdown
Member Author

@LeVraiArdox things should be good now.

The automated review has flagged ShapePath.trim a few times, but it does exist as it's a property group (QQuickShapeTrim), added in Qt 6.10, which has been out since October 2025 (and my machine runs 6.12.0).
It can be confirmed in one line:

grep -A3 'name: "trim"' /usr/lib/qt6/qml/QtQuick/Shapes/plugins.qmltypes

I did try the DashLine alternative it suggests instead: it renders fine in a plain Wayland window but never on the shell's layer-shell surface, so it would silently drop the countdown animation. Also, I thought colError would be better but ultimately decided to just stick with the original colPrimary

@LeVraiArdox LeVraiArdox left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

@LeVraiArdox
LeVraiArdox merged commit 369c1cb into main Nov 13, 2026
1 check passed
@LeVraiArdox
LeVraiArdox deleted the Critical-Actions branch November 23, 2026 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Critical Actions

2 participants